package com.tan.lbs.activity;

import com.tan.lbs.activity.R;
import com.tan.lbs.dao.GameDAO;
import com.tan.lbs.dao.QuestDAO;
import com.tan.lbs.dao.impl.GameDAOImpl;
import com.tan.lbs.dao.impl.QuestDAOImpl;
import com.tan.lbs.entity.Quest;
import com.tan.lbs.util.Constants;
import com.tan.lbs.util.ResourceReader;
import com.tan.lbs.util.URLs;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class QuestDetailActivity extends Activity{
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.questdetail);
		
		Intent intent = getIntent();
		String questID = intent.getStringExtra("questID");
		String gameID = getSharedPreferences(Constants.PREFS_NAME, 0).getString("currentGameID", "");
		QuestDAO questDAO = new QuestDAOImpl(this);
		Quest quest = questDAO.readQuest(questID, gameID);
		
		Bitmap icon = ResourceReader.readImage(this,
				URLs.gameResourceLoc + gameID + "/"
						+ quest.getIconID());
		
		ImageView questIcon = (ImageView)findViewById(R.id.questInfoIcon);
		questIcon.setImageBitmap(icon);
		

		
		((TextView)findViewById(R.id.questInfotitle)).setText(quest.getTitle());
		
		if(quest.getStatus().equals(Quest.START_STATUS) || quest.getStatus().equals(Quest.COMPLETE_STATUS)) {
			((TextView)findViewById(R.id.questStartText)).setText(quest.getStartText());
		} else {
			((TextView)findViewById(R.id.questStartText)).setText("Check in the quest to uncover more message.");
		}
		
		if(quest.getStatus().equals(Quest.COMPLETE_STATUS)) {
			((TextView)findViewById(R.id.questCompleteText)).setText(quest.getCompleteText());
		} else {
			((TextView)findViewById(R.id.questCompleteText)).setText("Finish the quest to uncover more message.");
		}
		
		((TextView)findViewById(R.id.questDuration)).setText(quest.getDuration());
		
		((Button)findViewById(R.id.questBackBtn)).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
			
		});
	}
}
